package com.websocket.websocket.service;

import com.websocket.websocket.config.CustomHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.TextMessage;

/**
 * @author ypz
 * @date 2021/9/6 14:04
 */
@Service
@EnableScheduling
public class SendMessageTest {
    @Autowired
    private CustomHandler customHandler;

    @Scheduled(cron = "0/5 * * * * ?")
    public void sendMessage(){
        customHandler.sendMessageToUser("10",new TextMessage("hello,这是由服务器发送的消息！"));
    }
}
